package com.longkey.workflow.client.canvas
{
	import flash.display.Graphics;
	import flash.display.GraphicsStroke;
	import flash.display.IGraphicsData;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import spark.primitives.supportClasses.StrokedElement;
	
	public class Angle extends StrokedElement
	{
		public function Angle()
		{
			super();
		}
		
		protected var _x0:Number = 0;
		protected var _y0:Number = 0;
		protected var _x1:Number = 0;
		protected var _y1:Number = 0;
		protected var _x2:Number = 0;
		protected var _y2:Number = 0;
		
		[Inspectable(category="General")]
		public function get x0():Number{
			return this._x0;
		}
		
		public function set x0(num:Number):void{
			if(this._x0 != num){
				this._x0 = num;
				this.invalidateSize();
				this.invalidateDisplayList();
			}
		}
		
		[Inspectable(category="General")]
		public function get x1():Number{
			return this._x1;
		}
		
		public function set x1(num:Number):void{
			if(this._x1 != num){
				this._x1 = num;
				this.invalidateSize();
				this.invalidateDisplayList();
			}
		}
		
		[Inspectable(category="General")]
		public function get x2():Number{
			return this._x2;
		}
		
		public function set x2(num:Number):void{
			if(this._x2 != num){
				this._x2 = num;
				this.invalidateSize();
				this.invalidateDisplayList();
			}
		}
		
		[Inspectable(category="General")]
		public function get y0():Number{
			return this._y0;
		}
		
		public function set y0(num:Number):void{
			if(this._y0 != num){
				this._y0 = num;
				this.invalidateSize();
				this.invalidateDisplayList();
			}
		}
		
		[Inspectable(category="General")]
		public function get y1():Number{
			return this._y1;
		}
		
		public function set y1(num:Number):void{
			if(this._y1 != num){
				this._y1 = num;
				this.invalidateSize();
				this.invalidateDisplayList();
			}
		}
		
		[Inspectable(category="General")]
		public function get y2():Number{
			return this._y2;
		}
		
		public function set y2(num:Number):void{
			if(this._y2 != num){
				this._y2 = num;
				this.invalidateSize();
				this.invalidateDisplayList();
			}
		}
		
		
		override protected function canSkipMeasurement():Boolean
		{
			return false;
		}
		
		override protected function measure():void
		{
			var minX:Number = Math.min(_x0, _x1, _x2);
			var minY:Number = Math.min(_y0, _y1, _y2);
			var maxX:Number = Math.max(_x0, _x1, _x2);
			var maxY:Number = Math.max(_y0, _y1, _y2);
			measuredWidth = maxX - minX;
			measuredHeight = maxY - minY;
			measuredX = minX;
			measuredY = minY;
		}
		
		override protected function beginDraw(g:Graphics):void
		{
			var graphicsStroke:GraphicsStroke; 
			if (stroke)
				graphicsStroke = GraphicsStroke(stroke.createGraphicsStroke(new 
					Rectangle(drawX + measuredX, drawY + measuredY, 
						Math.max(width, stroke.weight), Math.max(height, stroke.weight)),
					new Point(drawX + measuredX, drawY + measuredY))); 
			
			// If the stroke returns a valid graphicsStroke object which is the 
			// Drawing API-2 drawing commands to render this stroke, use that 
			// to draw the stroke to screen 
			if (graphicsStroke)
				g.drawGraphicsData(new <IGraphicsData>[graphicsStroke]);
			else 
				super.beginDraw(g);
		}
		
		override protected function draw(g:Graphics):void
		{
			g.moveTo(_x0 + drawX, _y0 + drawY);
			g.lineTo(_x1 + drawX, _y1 + drawY);
			g.lineTo(_x2 + drawX, _y2 + drawY);
		}
	}
}